//动态导入json数据

var xmlRequest = createXHQ();

xmlRequest.open("GET","../json/orderForm.json");
xmlRequest.send();

xmlRequest.onreadystatechange=function(){
	
	if(xmlRequest.readyState===4){
		if(xmlRequest.status===200){
			var result1 = xmlRequest.responseText;
			var resultObject = JSON.parse(result1);	
			
//						alert(resultObject.userId);
			
			var userLogin = document.getElementsByClassName("s2")[0].getElementsByTagName("a")[0];
			if(resultObject.userId!=null&&resultObject.userId!=""){
				userLogin.innerHTML=resultObject.userName;
				userLogin.href="../user_more.html";
			}
			
			var f_div = document.getElementsByClassName("mains")[0];
			var lastChild = document.getElementsByClassName("main-foot")[0];
			
			
			for(var i=0;i<resultObject.orderForm.length;i++){
				
				var divs = document.createElement("div");
				divs.className="main-s";
				
				var orderItem = "";
				for(var j=1;j<resultObject.orderForm[i].orderItem.length;j++){
					orderItem += "<tr>"+
									"<td class='main-table-t1'>"+
										"<div>"+
											"<img src="+ resultObject.orderForm[i].orderItem[j].shopImg +"/>"+
											"<span class='table-t-s'>"+ resultObject.orderForm[i].orderItem[j].shopTitle +"</span>"+
										"<span class='number'>x"+ resultObject.orderForm[i].orderItem[j].shopNum +"</span>"+
										"</div>"+
									"</td>"+
								"</tr>";
								
				}
				
				var text1 = "<table class='mains-table'>"+
								"<thead>"+
									"<tr>"+
										"<td  colspan='5'>"+
											"<span class='mains-table-time'>"+
												resultObject.orderForm[i].orderDate+" "+resultObject.orderForm[i].orderTime+
											"</span>"+
											"<span class='mains-table-time'>"+
												"订单号：<em>"+ resultObject.orderForm[i].orderId +"</em>"+
											"</span>"+
										"</td>"+
									"</tr>"+
								"</thead>"+
								"<tbody>"+
									"<tr>"+
										"<td class='main-table-t1'>"+
											"<div>"+
												"<img src="+ resultObject.orderForm[i].orderItem[0].shopImg +" />"+
												"<span class='table-t-s'>"+ resultObject.orderForm[i].orderItem[0].shopTitle +"</span>"+
												"<span class='number'>x"+ resultObject.orderForm[i].orderItem[0].shopNum +"</span>"+
											"</div>"+
										"</td>"+
										"<td class='main-table-t2' rowspan="+ resultObject.orderForm[i].orderItem.length +">"+
											resultObject.orderForm[i].siteUser+
										"</td>"+
										"<td class='main-table-t2' rowspan="+ resultObject.orderForm[i].orderItem.length +">"+
											"总额：￥<em>"+ resultObject.orderForm[i].orderMoney +"</em>"+
										"</td>"+
										"<td class='main-table-t2' rowspan="+ resultObject.orderForm[i].orderItem.length +">"+
											resultObject.orderForm[i].orderState+
										"</td>"+
										"<td class='main-table-t2' rowspan="+ resultObject.orderForm[i].orderItem.length +"></td>"+
									"</tr>"+
									orderItem+
								"</tbody>"+
							"</table>";
				
				divs.innerHTML = text1;
				
				
				f_div.insertBefore(divs,lastChild);
				
			}
		}else{
			alert("错误信息："+xmlRequest.status);
		}
	}
}